var s = getApp();

Page({
    data: {
        addressListData: [],
        state: 0,
        show_add_address: !0
    },
    _getData: function() {
        var t = this;
        s._getNetWork({
            showToastIn: !1,
            url: s.getNetAddresss("member.member-address.index"),
            success: function(s) {
                var e = s.data;
                if (1 == e.result) {
                    var a = 0;
                    a = e.data.length <= 0 ? 1 : 2, t.setData({
                        addressListData: e.data,
                        state: a
                    }), console.log("收货地址列表", e.data);
                } else wx.showToast({
                    title: "数据错误",
                    icon: "success",
                    duration: 2e3,
                    success: function() {},
                    fail: function() {}
                });
            },
            fail: function(s) {}
        });
    },
    defaultAddress: function(t) {
        var e = this, a = s.getNetAddresss("member.member-address.setDefault");
        a += "&address_id=" + t.currentTarget.dataset.id, s._getNetWork({
            url: a,
            success: function(s) {
                var t = s.data;
                console.log("设置默认收货地址", s), 1 == t.result ? e._getData() : wx.showToast({
                    title: t.msg,
                    icon: "none",
                    duration: 2e3,
                    success: function() {},
                    fail: function() {}
                });
            },
            fail: function(s) {}
        });
    },
    editAddress: function(s) {
        var t = s.currentTarget.dataset.item;
        wx.navigateTo({
            url: "/packageD/member/addressEdit/addressEdit?model=" + JSON.stringify(t)
        });
    },
    delAddress: function(t) {
        var e = this, a = s.getNetAddresss("member.member-address.destroy");
        a += "&address_id=" + t.currentTarget.dataset.id, wx.showModal({
            title: "提示",
            content: "确定要删除么？此操作不可逆！",
            success: function(t) {
                t.confirm && (console.log("用户点击确定"), s._getNetWork({
                    url: a,
                    success: function(s) {
                        var t = s.data;
                        console.log("收货地址列表", t), 1 == t.result ? (e._getData(), wx.showToast({
                            title: t.msg,
                            icon: "success",
                            duration: 2e3,
                            success: function() {},
                            fail: function() {}
                        })) : wx.showToast({
                            title: "数据错误",
                            icon: "success",
                            duration: 2e3,
                            success: function() {},
                            fail: function() {}
                        });
                    },
                    fail: function(s) {}
                }));
            }
        });
    },
    _gotoAddressAdd: function(s) {
        var t = !0;
        if (this.data.addressListData.length > 0) for (var e = 0; e < this.data.addressListData.length; e++) 1 == this.data.addressListData[e].isdefault && (t = !1);
        wx.navigateTo({
            url: "/packageD/member/addressAdd_v2/addressAdd_v2?isdefault=" + t
        });
    },
    updateAdress: function() {
        wx.showLoading({
            title: "更新缓存中"
        }), wx.removeStorage({
            key: "provinceData",
            success: function(s) {
                console.log(s), wx.hideLoading({
                    success: function(s) {
                        wx.showToast({
                            title: "更新成功",
                            icon: "none",
                            duration: 1e3
                        });
                    }
                });
            },
            fail: function(s) {
                wx.hideLoading({
                    success: function(s) {
                        wx.showToast({
                            title: "更新失败",
                            icon: "none",
                            duration: 1e3
                        });
                    }
                });
            }
        });
    },
    onLoad: function(s) {},
    onReady: function() {},
    onShow: function() {
        this._getData();
        var s = wx.getStorageSync("yz_basic_info");
        if (s.plugin_setting && s.plugin_setting.address_code) {
            var t = s.plugin_setting.address_code;
            this.setData({
                show_add_address: t.show_add_address
            });
        }
        this.setData({
            address_parse_open: s.plugin_setting.address_parse_open ? s.plugin_setting.address_parse_open : 0
        });
    },
    onHide: function() {},
    onUnload: function() {}
});